<?php
namespace app\index\controller;
use app\index\model\Cases;
use app\index\model\FriendshipLink;
use app\index\model\Information;
use app\index\model\InformationClassification;
use think\Config;
use app\index\model\Designer;
use app\index\model\Drawing;
use app\index\model\System;


class index extends Base
{
    /**
     * Author:yang you
     * Time:2018-11-15 10:00:43
     * Describe:首页
     * @return \think\response\View
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index()
    {

        $config = new \app\index\model\Config();
        $keyword = input("keyword/s");
        $Drawing = new Drawing();
        $designer = new Designer();
        $system = new System();
        //图纸风格种类
        $systemInfo = $system->systemInfo("detailSetting");
        $drawingType = json_decode($systemInfo["system_content"]);
        $drawingType = $drawingType->index_style;
        if(!empty($drawingType)){
            foreach ($drawingType as $key=>$val){
                $indexDrawingType[$key]["drawingType"] = $config->info($val);
                $indexDrawingType[$key]["drawingList"] = $Drawing->drawingList($keyword,$val,$layct = "",$structure="",$house="",$is_top="1");
            }
        }
        //设计师团队
        $team = $designer->team();
        //施工案例
        Config::load(APP_PATH.'admin/config.php');//加载上传配置文件
        $ImgApiData = config("ImgApiData");
        $cases = new Cases();
        $caseList = $cases->caseList($style="",$layct="",$is_top="1");
        foreach ($caseList as $key=>$val){//获取市名字
            $shenList = $this->http_request($ImgApiData["domain"].'/'.$ImgApiData["ApiList"]["addressList"], ["pid"=>0]);
            $shiList = $this->http_request($ImgApiData["domain"].'/'.$ImgApiData["ApiList"]["addressList"], ["pid"=>$val['sheng']]);
            $shenList = json_decode($shenList);
            foreach ($shenList->data as $v){
                if($v->id == $val['sheng']){
                    $caseList[$key]['shenName'] = $v->name;
                    break;
                }elseif($val['sheng']==0){
                    $caseList[$key]['shenName'] = '';
                    break;
                }
            }
            $shiList = json_decode($shiList);
            foreach ($shiList->data as $v){
                if($v->id == $val['shi']){
                    $caseList[$key]['shiName'] = $v->name;
                    break;
                }elseif ($val['shi']==0){
                    $caseList[$key]['shiName'] = '';
                    break;
                }
            }
        }
        //定制案例
        $orderCaseList = $cases->caseList($style="",$layct="",$is_top="1",$classification_id="12");
        foreach ($orderCaseList as $key=>$val){//获取市名字
            $shenList = $this->http_request($ImgApiData["domain"].'/'.$ImgApiData["ApiList"]["addressList"], ["pid"=>0]);
            $shiList = $this->http_request($ImgApiData["domain"].'/'.$ImgApiData["ApiList"]["addressList"], ["pid"=>$val['sheng']]);
            $shenList = json_decode($shenList);
            foreach ($shenList->data as $v){
                if($v->id == $val['sheng']){
                    $orderCaseList[$key]['shenName'] = $v->name;
                    break;
                }
            }
            $shiList = json_decode($shiList);
            foreach ($shiList->data as $v){
                if($v->id == $val['shi']){
                    $orderCaseList[$key]['shiName'] = $v->name;
                    break;
                }
            }
        }
        //友情链接
        $FriendShipLink = new FriendshipLink();
        $linkList = $FriendShipLink->friendshipLinkList();
        //咨询新闻
        $informationClassification = new InformationClassification();
        $information = new Information();
        //资讯类型
        $informationType = $informationClassification->informationClassificationList($parent_id="",$is_index="1");
        //子分类
        foreach ($informationType as $key=>$val){
            $informationType[$key]['informationList'] = $information->informationList($val['classification_id'],$limit = "15",$left="5",$center="10");//下面四款最热门的别墅图片
        }
        //热门标签
        $hotTag =  $information->randKeywordInfo();
        return view('home/index',[
            'indexDrawingType' => $indexDrawingType,
            'team' => $team,
            'caseList' => $caseList,
            'orderCaseList' => $orderCaseList,
            'linkList' => $linkList,
            'informationType' => $informationType,
            'hotTag' => $hotTag
        ]);
    }
}